import http from '../api/http'
import type { ApiResult, PageResult } from './types'

// 收款码响应类型（对齐后端 PaymentCodeRequestDto 的主要字段）
export interface PaymentCodeResponse {
  id?: string
  code?: string
  codeName?: string
  codeUrl?: string
  creationTime?: string
  enableStatus?: number
  merchantId?: string
  storeId?: string
  storeName?: string
  parentId?: string
  dividedAgreementId?: string
  settlementCycle?: number
  bindUserName?: string[]
}

export class PaymentCodeService {
  // 获取收款码列表
  static async getPaymentCodeList(
    page: number = 1,
    limit: number = 10,
    key: string = '',
    storeId?: string,
    merchantId?: string,
    queryNoDividedAgreement?: boolean
  ): Promise<ApiResult<PageResult<PaymentCodeResponse>>> {
    const resp = await http.get<ApiResult<PageResult<PaymentCodeResponse>>>(
      '/PaymentCode/GetPaymentCodeList',
      {
        params: {
          page,
          limit,
          key,
          storeId: storeId || '',
          merchantId: merchantId || '',
          queryNoDividedAgreement
        }
      }
    )
    return resp.data
  }

  // 获取单个收款码详情（支持通过 id 或 code 查询）
  static async getPaymentCodeDetail(params: { id?: string; code?: string }): Promise<ApiResult<PaymentCodeResponse>> {
    const resp = await http.get<ApiResult<PaymentCodeResponse>>('/PaymentCode/GetPaymentCodeDetail', { params })
    return resp.data
  }
}

